package cn.core.tool.interceptors;

import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 字符串类型请求参数去首尾空格
 */
@RestControllerAdvice
@ConditionalOnProperty(prefix = "proconf", name = "trim-interceptor", havingValue = "true")
public class TrimAdvice {

  @InitBinder
  public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
  }

}
